<?php
namespace app\api\controller;
use app\model\Banner as BannerModel;
use app\model\Token as TokenModel;
use think\Db;


class Banner extends Base
{   
    /**
     * @Author   CCH
     * @DateTime 2020-05-23T12:10:10+0800
     * @return   数据列表
     */
    public function index(){
        // $map_params = [
            
        // ];
        // $map = getSearchParam($map_params);
        // $map[] = ['status','=',1];

        // $model = new BannerModel();

        // $list = $model->where($map)->order('sort desc,id desc')->select();
        // foreach ($list['data'] as $k => $vo) {
            
        // }
        // return apiResult('2000','获取成功',$list);

        $model = new BannerModel();
        $data = $model->where([
            ['status','=',1],
            ['type','=',1]
        ])->find();

        if ( empty($data) ) {
            $data = $model->where([
                ['status','=',1],
                ['type','=',0]
            ])->order('sort desc,id desc')->select();
            if (count($data) == 1) {
                $data = $data[0];
            }
        }

        return apiResult('2000','获取成功',$data);
    }

    /**
     * 获取详情
     * @Author   cch
     * @DateTime 2020-05-26T17:22:45+0800
     * @return   [type]                   [description]
     */
    public function read($id){
        $model = new BannerModel();
        $data = $model->where('id',$id)->find();
        return apiResult('2000','获取成功',$data);
    }

   


}
